package com.heima.controller;


import com.heima.pojo.TbRegion;
import com.heima.pojo.dto.TbRegionDto;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.TbRegionVo;
import com.heima.service.ITbRegionService;
import com.heima.service.impl.TbRegionServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 运营区域 前端控制器
 * </p>
 *
 * @author AkiRinko
 * @since 2024-06-07
 */
@RestController
@RequestMapping("/api/vm-service/region")
@RequiredArgsConstructor
public class TbRegionController {
    private final ITbRegionService tbRegionService;

    /**
     * 区域搜索
     *
     * @return
     */
    @GetMapping("/search")
    private PageResponse<TbRegionVo> selectRegionPage(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                                      @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                      @RequestParam(value = "name", required = false) String name) {
        return tbRegionService.selectRegionPage(pageIndex, pageSize, name);
    }

    /**
     * 新增区域
     * @param dto
     */
    @PostMapping
    private void insertRegion(@RequestBody TbRegionDto dto) {
        tbRegionService.insertRegion(dto);
    }

    /**
     * 修改区域
     * @param regionId
     * @param dto
     */
    @PutMapping("/{regionId}")
    private void updateRegion(@PathVariable String regionId,
                              @RequestBody TbRegionDto dto){
        tbRegionService.updateRegion(regionId, dto);
    }

    /**
     * 删除区域
     * @param regionId
     */
    @DeleteMapping("/{regionId}")
    private void deleteRegion(@PathVariable String regionId){
        tbRegionService.deleteRegion(regionId);
    }
}
